import requests
import logging
class Test():
    uid=""
    sid=""
    def setup_method(self):
        print("初始化环境，开始执行用例")
    def teardown_method(self):
        print("优化环境，用例执行结束")
    #登录
    def test_denglu(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            body={"phone":"13811033965","pwd":"123456Aa"}
            headers={"Content-Type":"application/json"}
            r=requests.post(url=url,json=body,headers=headers)
            print(r.json())
            assert r.status_code==200
            assert '登录成功' in r.text
            assert r.json()["result"]["nickName"]=="韩坤1号"
        except Exception as f:
            logging.info(f)
            Test.sid=r.json()["result"]["sessionId"]
            Test.uid=r.json()["result"]["userId"]
    #首页商品信息列表
    def test_chakan(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/commodityList"
            headers={"Content-Type":"application/json"}
            r=requests.get(url=url,headers=headers)
            print(r.json())
            assert r.status_code==200
            assert '查询成功' in r.text
            assert r.json()["result"]["rxxp"]["commodityList"][0]["commodityName"]=="秋冬增高休闲鞋厚底棉鞋运动户外通勤简约韩版女鞋"
        except Exception as f:
            logging.info(f)
    #商品详情页面
    def test_shangpin(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/findCommodityDetailsById?commodityId=27"
            body={"userId":Test.uid,"sessionId":Test.sid}
            headers={"Content-Type":"application/json"}
            r=requests.get(url=url,params=body,headers=headers)
            print(r.json())
            assert r.status_code==200
            assert '休闲马衔扣保暖绒里棉鞋懒人鞋毛毛鞋平底女雪地靴女短靴子豆豆鞋女鞋' in r.text
            assert r.json()["result"]["categoryName"]=="女鞋"
        except Exception as f:
            logging.info(f)
    #创建订单
    def test_chuang(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/createOrder"
            body={"orderInfo":{"commodityId":27,"amount":1},"totalPrice":"95","addressId":1}
            headers={"userId":Test.uid,"sessionId":Test.sid}
            r=requests.post(url=url,data=body,headers=headers)
            print(r.json())
            assert r.status_code==200
            assert '创建成功' in r.text
            assert r.json()["message"]=="创建成功"
        except Exception as f:
            logging.info(f)
    #支付
    def test_xiadan(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/pay"
            body={"orderId":"1441165","payType":"1"}
            headers={"userId":Test.uid,"sessionId":Test.sid}
            r=requests.post(url=url,data=body,headers=headers)
            print(r.json())
            assert r.status_code==200
            assert '支付成功' in r.text
            assert r.json()["message"]=="支付成功"
        except Exception as f:
            logging.info(f)